# Required packages for our course. Do not delete.
library(tidyverse)
library(mosaic)
How did Kobe Bryant’s scoring and overall performance metrics (such as assists, rebounds, and points) evolve throughout his career?
This question aims to explore the trajectory of Kobe Bryant’s performance over his NBA career, highlighting his development and consistency as a player. Through visualization, I hope to illustrate not just his scoring ability, which he is widely renowned for, but also how his contributions in other aspects of the game changed over time. This could provide insights into his adaptability, growth as a player, and how his role within the Los Angeles Lakers evolved. By analyzing the patterns and trends in his performance metrics across different seasons, we can appreciate the breadth of his impact on basketball.
The dataset comprises detailed game-by-game statistics of Kobe Bryant’s NBA career, focusing on various performance metrics such as points scored, assists, rebounds, steals, blocks, turnovers, and personal fouls, among others. It includes data from each game, specifying the date, Kobe’s age at the time of the game, the team played for (Los Angeles Lakers), whether it was a regular season or playoff game, the game’s venue, the opponent team, and the game’s outcome in terms of win or loss and point difference. Additional details include whether Kobe started the game, minutes played, and shooting efficiency (field goals, three-pointers, and free throws).
Include the code to load your data here. Using the head() function, show the first 10 rows of data.
file_path <- "C:/Users/shrir/OneDrive/Desktop/kobebryant.csv"
# Load the dataset
kobe_bryant <- read.csv(file_path, header = TRUE, stringsAsFactors = FALSE)
# Display the first 10 rows using the head() function
head(kobe_bryant, 10)
| season | date | age | team_played | game_type | venue | opponent | win_lose | point_difference | game_started | minutes_played | fieldgoal | fieldgoal_attempts | fieldgoal_percent | X3pointers | X3pointers_attempts | X3pointers_percent | freethrows | freethrows_attempt | freethrow_percent | offensive_rebounds | defensive_rebounds | total_rebounds | assists | steals | blocks | turnovers | personal_fouls | points |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 1 | 11/1/1996 | 18 | los angeles lakers | season | away | phoenix suns | w | 14 | Null | Null | Null | Null | Null | Null | Null | Null | Null | Null | Null | Null | Null | Null | Null | Null | Null | Null | Null | Null |
| 1 | 11/3/1996 | 18 | los angeles lakers | season | away | minnesota timberwolves | w | 6 | 0 | 6:22 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 1 | 0 | 0 | 1 | 1 | 1 | 0 | ||
| 1 | 11/5/1996 | 18 | los angeles lakers | season | home | new york knicks | w | 6 | 0 | 3:16 | 0 | 1 | 0 | 0 | 0 | 1 | 2 | 0.5 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 1 | |
| 1 | 11/6/1996 | 18 | los angeles lakers | season | home | charlotte hornets | l | -10 | 0 | 6:49 | 2 | 3 | 0.667 | 1 | 2 | 0.5 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 3 | 0 | 5 | |
| 1 | 11/8/1996 | 18 | los angeles lakers | season | home | toronto rapters | l | -1 | 0 | 17:15 | 3 | 8 | 0.375 | 2 | 3 | 0.667 | 2 | 4 | 0.5 | 0 | 3 | 3 | 0 | 0 | 1 | 0 | 3 | 10 |
| 1 | 11/10/1996 | 18 | los angeles lakers | season | away | atlanta hawks | w | 7 | 0 | 8:25 | 0 | 3 | 0 | 0 | 0 | 2 | 2 | 1 | 1 | 2 | 3 | 1 | 0 | 0 | 0 | 0 | 2 | |
| 1 | 11/12/1996 | 18 | los angeles lakers | season | home | houston rockets | w | 11 | 0 | 5:03 | 1 | 2 | 0.5 | 0 | 1 | 0 | 0 | 0 | 0 | 1 | 1 | 0 | 0 | 0 | 2 | 0 | 2 | |
| 1 | 11/13/1996 | 18 | los angeles lakers | season | home | san antonio spurs | l | -12 | 0 | 6:06 | 2 | 2 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 2 | 6 |
| 1 | 11/15/1996 | 18 | los angeles lakers | season | away | los angeles clippers | w | 7 | 0 | 7:01 | 1 | 4 | 0.25 | 0 | 2 | 0 | 2 | 3 | 0.667 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 4 | 4 |
| 1 | 11/17/1996 | 18 | los angeles lakers | season | home | phoenix suns | w | 14 | 0 | 14:29 | 5 | 8 | 0.625 | 4 | 6 | 0.667 | 2 | 2 | 1 | 2 | 0 | 2 | 2 | 0 | 0 | 4 | 2 | 16 |
Using the names() function, show the names of all the columns (i.e. potential variables) in your data set. Delete this when complete.
names(kobe_bryant)
## [1] "season" "date" "age"
## [4] "team_played" "game_type" "venue"
## [7] "opponent" "win_lose" "point_difference"
## [10] "game_started" "minutes_played" "fieldgoal"
## [13] "fieldgoal_attempts" "fieldgoal_percent" "X3pointers"
## [16] "X3pointers_attempts" "X3pointers_percent" "freethrows"
## [19] "freethrows_attempt" "freethrow_percent" "offensive_rebounds"
## [22] "defensive_rebounds" "total_rebounds" "assists"
## [25] "steals" "blocks" "turnovers"
## [28] "personal_fouls" "points"
The variables I used in my data visualization design are:
#season - To analyze performance across different seasons.
#points - For insights on scoring trends.
#game_type - To distinguish between regular season and playoff performances.
#win_lose - To correlate Kobe’s performance with team success.
#fieldgoal_percent - To evaluate shooting efficiency over time.
Using the favstats() function, calculate the necessary statistics you used to create your data visualization. Delete this when complete.
# Convert necessary columns to numeric, handling non-numeric entries
kobe_bryant$points <- as.numeric(as.character(kobe_bryant$points))
# Calculate favorite statistics for points
points_stats <- favstats(~ points, data = kobe_bryant)
print(points_stats)
## min Q1 median Q3 max mean sd n missing
## 0 18 25 32 81 25.0869 10.60878 1565 212
Provide the high-level insights you used to craft your data visualization design.
If you conducted any other analyses of your data set to gather the data in your project, use this section to conduct your research. Delete this when complete.
Opening Timeline of Career Highlights
library(ggplot2)
library(plotly)
library(dplyr)
# Convert factors to characters to ensure they work well with plotly
kobe_bryant$season <- as.character(kobe_bryant$season)
# Ensure 'points' is numeric for calculations
kobe_bryant$points <- as.numeric(as.character(kobe_bryant$points))
# Calculate average points per season
avg_points_per_season <- kobe_bryant %>%
group_by(season) %>%
summarise(avg_points = mean(points, na.rm = TRUE))
# Create the ggplot
p <- ggplot(avg_points_per_season, aes(x = season, y = avg_points)) +
geom_line() +
geom_point() +
theme_minimal() +
labs(title = "Kobe Bryant's Average Points per Season",
x = "Season",
y = "Average Points")
# Convert ggplot to an interactive plotly object
interactive_p <- ggplotly(p)
# Print the interactive plot to the Viewer in RStudio or in your R environment
print(interactive_p)
library(ggplot2)
library(plotly)
# Find the top scoring games
top_scoring_games <- kobe_bryant %>%
arrange(desc(points)) %>%
top_n(10, points)
# Plot
top_games_plot <- ggplot(top_scoring_games, aes(x = reorder(date, points), y = points)) +
geom_col() +
coord_flip() +
labs(title = "Top 10 Scoring Games of Kobe Bryant's Career",
x = "Date of Game", y = "Points Scored") +
theme_minimal()
# Make interactive
top_games_interactive <- ggplotly(top_games_plot)
top_games_interactive
# Calculate average points per season
seasonal_points <- kobe_bryant %>%
group_by(season) %>%
summarise(avg_points = mean(points, na.rm = TRUE))
# Plot
seasonal_points_plot <- ggplot(seasonal_points, aes(x = season, y = avg_points)) +
geom_line() +
geom_point() +
labs(title = "Seasonal Scoring Consistency Over Kobe Bryant's Career",
x = "Season", y = "Average Points per Game") +
theme_minimal()
# Make interactive
seasonal_points_interactive <- ggplotly(seasonal_points_plot)
seasonal_points_interactive
clutch_performances <- kobe_bryant %>%
filter(point_difference <= 5, minutes_played >= '00:45:00') %>%
mutate(final_minutes_points = as.numeric(points))
plot_ly(clutch_performances, x = ~season, y = ~final_minutes_points, type = 'scatter', mode = 'markers') %>%
layout(title = "Kobe Bryant's Clutch Performances", xaxis = list(title = "Season"), yaxis = list(title = "Points in Final Minutes"))
library(ggplot2)
library(plotly)
# Example data frame with milestones
milestones <- data.frame(
year = c(1996, 2000, 2006, 2010, 2016),
event = c("NBA Debut", "1st Championship", "81 Points Game", "5th Championship", "Retirement"),
y = rep(1, 5) # Same y level for all points, you can adjust this for better positioning
)
# Plotting the timeline
milestone_plot <- ggplot(milestones, aes(x = year, y = y, label = event)) +
geom_line(aes(group = 1)) + # One group for all points
geom_point() + # Add points to the timeline
geom_text(nudge_y = 0.1) + # Slightly nudge text above the points
labs(title = "Kobe Bryant's Career Milestones",
x = "Year",
y = "") + # Remove y-axis label
theme_minimal() +
theme(axis.line.y = element_blank(), # Remove y-axis line
axis.text.y = element_blank(), # Remove y-axis text
axis.ticks.y = element_blank()) # Remove y-axis ticks
# Making it interactive
interactive_milestone_plot <- ggplotly(milestone_plot)
# Save the interactive plot if needed
htmlwidgets::saveWidget(interactive_milestone_plot, "milestone_plot.html")
library(ggplot2)
library(dplyr)
library(plotly)
# Assuming 'points' and 'opponent' are in your dataset and 'season' is in the format 'YYYY-YY'
scoring_heatmap_data <- kobe_bryant %>%
group_by(season, opponent) %>%
summarise(avg_points = mean(points, na.rm = TRUE), .groups = 'drop') %>%
arrange(opponent, season)
p <- ggplot(scoring_heatmap_data, aes(x = season, y = reorder(opponent, -avg_points), fill = avg_points)) +
geom_tile() +
scale_fill_gradient(low = "blue", high = "red") +
labs(title = "Kobe Bryant's Average Points Per Game Across Seasons",
x = "Season",
y = "Opponent") +
theme_minimal() +
theme(axis.text.x = element_text(angle = 90, vjust = 0.5))
# Make it interactive
ggplotly(p)
# Histogram of Kobe's points
p5 <- ggplot(kobe_bryant, aes(x = points)) +
geom_histogram(binwidth = 5, fill = "blue", color = "white") +
theme_minimal() +
labs(title = "Kobe Bryant's Career Points Distribution", x = "Points", y = "Frequency")
ggplotly(p5)
library(ggplot2)
library(plotly)
library(dplyr)
# Ensure 'points' is numeric
kobe_bryant$points <- as.numeric(as.character(kobe_bryant$points))
# Filter data for early years and calculate average points per season
early_years <- kobe_bryant %>%
mutate(season = as.character(season)) %>% # Convert season to character if it's not
filter(season <= "1999-00") %>%
group_by(season) %>%
summarise(avg_points = mean(points, na.rm = TRUE))
# Plotting
p <- ggplot(early_years, aes(x = season, y = avg_points)) +
geom_line() +
geom_point() +
labs(title = "Kobe's Rise to Stardom: Points Per Game in Early Seasons",
x = "Season",
y = "Average Points") +
theme_minimal()
ggplotly(p)
# Convert assists to numeric
kobe_bryant$assists <- as.numeric(as.character(kobe_bryant$assists))
# Create a summary of average assists against each opponent
assist_heatmap_data <- kobe_bryant %>%
group_by(opponent) %>%
summarise(avg_assists = mean(assists, na.rm = TRUE)) %>%
arrange(desc(avg_assists))
# Create the heatmap
p <- ggplot(assist_heatmap_data, aes(x = reorder(opponent, -avg_assists), y = avg_assists)) +
geom_tile(aes(fill = avg_assists)) +
scale_fill_gradient(low = "blue", high = "red") +
labs(title = "Kobe Bryant's Average Assists Against Each Opponent",
x = "Opponent",
y = "Average Assists") +
theme_minimal() +
theme(axis.text.x = element_text(angle = 90, hjust = 1))
# Convert to interactive plot
interactive_heatmap <- ggplotly(p)
# Save the interactive plot as HTML
htmlwidgets::saveWidget(interactive_heatmap, 'kobe_assists_heatmap.html', selfcontained = TRUE)
# Convert points to numeric if it's not already
kobe_bryant$points <- as.numeric(as.character(kobe_bryant$points))
# Identify the peak performances
peak_performances <- kobe_bryant %>%
arrange(desc(points)) %>%
select(season, date, opponent, points) %>%
head(n = 10) # You can change 'n' to see more or fewer performances
# Display the table
print(peak_performances)
## season date opponent points
## 1 10 1/22/2006 toronto rapters 81
## 2 11 3/16/2007 portland trailbrazers 65
## 3 10 12/20/2005 dallas mavericks 62
## 4 13 2/2/2009 new york knicks 61
## 5 11 3/22/2007 memphis grizzlies 60
## 6 20 4/13/2016 utah jazz 60
## 7 11 12/29/2006 charlotte hornets 58
## 8 6 1/14/2002 memphis grizzlies 56
## 9 7 3/28/2003 washington wizards 55
## 10 11 12/15/2006 houston rockets 53
# Ensure the necessary columns are numeric
kobe_bryant$points <- as.numeric(as.character(kobe_bryant$points))
kobe_bryant$assists <- as.numeric(as.character(kobe_bryant$assists))
kobe_bryant$total_rebounds <- as.numeric(as.character(kobe_bryant$total_rebounds))
# Calculate a simple 'Performance Score' for each game
kobe_bryant <- kobe_bryant %>%
mutate(performance_score = points + assists + total_rebounds)
# Find the top performances based on this score
top_performances <- kobe_bryant %>%
arrange(desc(performance_score)) %>%
select(season, date, opponent, points, assists, total_rebounds, performance_score) %>%
head(n = 10) # Adjust 'n' to show more or fewer performances
# Display the table
print(top_performances)
## season date opponent points assists total_rebounds
## 1 10 1/22/2006 toronto rapters 81 2 6
## 2 11 3/16/2007 portland trailbrazers 65 3 7
## 3 11 12/15/2006 houston rockets 53 8 10
## 4 10 12/20/2005 dallas mavericks 62 0 8
## 5 11 3/22/2007 memphis grizzlies 60 4 5
## 6 20 4/13/2016 utah jazz 60 4 4
## 7 5 5/13/2001 sacramento kings 48 3 16
## 8 7 2/18/2003 houston rockets 52 7 8
## 9 11 12/29/2006 charlotte hornets 58 4 5
## 10 12 3/2/2008 dallas mavericks 52 4 11
## performance_score
## 1 89
## 2 75
## 3 71
## 4 70
## 5 69
## 6 68
## 7 67
## 8 67
## 9 67
## 10 67
Module 3’s Project allows students to choose ONE OPTION among the two options provided below. You should denote which ONE of the two options you plan to pursue and provide a brief overview of your vision for the project. Delete the other options that you will not be pursuing.
Students will create a website that present their data findings and topic in a website where users can engage with their platform. Students must include a minimum of 5 pages of analysis, 1 page for their home, and 1 page for references/overview.
Link of my webpage
https://sites.google.com/view/kobe-bryant-insh5302/home?authuser=0
Page 1: Kobe’s Inception: The Making of a Legend This page delves into the formative years of Kobe Bryant’s career, examining how a young, ambitious athlete evolved into a future icon of basketball. Through interactive visualizations of his early performance, visitors can trace the steady climb of his skills and achievements, setting the foundation for a storied career.
Page 2: Dominance in Scoring Here we explore Kobe’s reputation as a scoring powerhouse. The data vividly illustrates his ability to consistently rack up points, regardless of the opponent or season. Interactive charts allow users to see just how Kobe’s scoring prowess made him one of the most feared offensive players in the NBA.
Page 3: Kobe - A Team Man! Moving beyond individual accolades, this page focuses on Kobe’s contributions to team success. With visualizations highlighting his assists and rebounds, we celebrate Kobe not just as a scorer, but as a true team player who elevated those around him through selfless play and strategic assists.
Page 4: Clutch Scoring: Kobe’s Playoff Dominance Kobe’s ability to perform under pressure is legendary, and this page’s interactive visualizations showcase his elevated game during playoffs. By examining his clutch scoring when it mattered most, this page illustrates how Kobe became synonymous with the term ‘clutch,’ solidifying his role as a pivotal player in crucial moments.
Page 5: Kobe’s Legacy The final page is a tribute to the enduring legacy of Kobe Bryant. It encapsulates his career through interactive timelines and milestone charts that narrate the story of a relentless competitor, an inspiring leader, and a cultural icon whose influence transcended the sport itself.
For each page, the data visualizations not only serve as evidence of Kobe’s basketball prowess but also as narrative tools that allow visitors to engage with his journey and understand the depth of his impact on the sport.
Kobe Bryant References >“Kobe Bryant Biography & Facts,” Biography.com, available at biography.com/athletes/kobe-bryant.
“Kobe Bryant’s Life, Lakers Career & Legacy,” Lakers Nation, available at lakersnation.com/kobe-bryant-biography-life-lakers-career-and-legacy.
“Exploring Kobe Bryant’s NBA Journey,” Kaggle dataset by Alfred Kondoro, available at kaggle.com/datasets/alfredkondoro/exploring-kobe-bryants-nba-journey.
Various images and information sourced from Google Images and Medium Data Science articles, with credits given to the photographers and authors where available.
Knit the completed R Markdown file as a HTML document (click the “Knit” button at the top of the script editor window) and upload it to the submission portal on Canvas.